package com.tom.system.controller;

import com.tom.basic.utils.AjaxResult;
import com.tom.basic.utils.PageList;
import com.tom.system.domain.Systemdictionarydetail;
import com.tom.system.domain.Systemdictionarytype;
import com.tom.system.query.SystemdictionarydetailQuery;
import com.tom.system.service.ISystemdictionarydetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(value = "部门的API",description="部门相关的CRUD功能")
@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {
    @Autowired
    private ISystemdictionarydetailService SystemdictionarydetailService;
    /**
     * @Title: 根据id查询
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
//    @ApiOperation(value = "通过ID查询" )
//    @GetMapping("/{id}")
//    public Systemdictionarydetail loadById(@ApiParam(value = "ID属性",required = true) @PathVariable("id")Long id){
//        return SystemdictionarydetailService.loadById(id);
//    }
    /**
     * @Title: 查询所有
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @GetMapping
    public List<Systemdictionarydetail> loadAll(){
        return SystemdictionarydetailService.loadAll();
    }
    @ApiOperation(value = "通过ID查询" )
    @GetMapping("/{types_id}")
    public List<Systemdictionarydetail> load(@ApiParam(value = "ID属性",required = true) @PathVariable("types_id")Long types_id){
     return SystemdictionarydetailService.load(types_id);
    }
    /**
     * @Title: 高级查询
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @PostMapping
    public PageList<Systemdictionarydetail> queryData(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery) {
        return SystemdictionarydetailService.queryData(systemdictionarydetailQuery);
    }
    /**
     * @Title: 根据id删除
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id")Long id){
        try {
            SystemdictionarydetailService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
        }
    }
    /**
     * @Title: 增加和删除
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @PutMapping
    public AjaxResult updateOrAdd(@RequestBody Systemdictionarydetail systemdictionarydetail) {
        try {
            if (systemdictionarydetail.getId() == null){
                SystemdictionarydetailService.save(systemdictionarydetail);
            } else {
                SystemdictionarydetailService.update(systemdictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
        }
    }
    /**
     * @Title: 批量删除
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @PatchMapping
    public AjaxResult batchDel(@RequestBody Long ids[]){
        try {
            SystemdictionarydetailService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
        }

    }
}
